package cn.ffcs.uec.staffRecords.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.staffRecords.dao.AtiSpecificFormDao;
import cn.ffcs.uec.staffRecords.vo.AtiOaBaseObject;
import cn.ffcs.uom.common.dao.BaseDaoImpl;

@Repository("atiSpecificFormDao")
@Transactional
public class AtiSpecificFormDaoImpl extends BaseDaoImpl implements AtiSpecificFormDao{

	@Override
	public AtiOaBaseObject getAtiOaBaseObjectByProcInstId(String procInstId) {
		StringBuilder builder = new StringBuilder(" select bf.ati_base_form_id as atiBaseFormId, "
				+ "bf.form_sender as formSender, "
				+ "bf.form_theme as formTheme, "
				+ "bf.form_content as formContent, "
				+ "bf.proc_def_id as procDefId, "
				+ "bf.proc_inst_id as procInstId, "
				+ "bf.urgent as urgent, "
				+ "bf.\"LEVEL\", "
				+ "sf.ati_act_category_id as atiActCategoryId, "
				+ "sf.staff_id as staffId, "
				+ "sf.out_staff_id as outStaffId, "
				+ "sf.trial_id as trialId, "
				+ "sf.psnjob_id_modify as psnjobIdModify, "
				+ "sf.psnjob_id_add as psnjobIdAdd, "
				+ "sf.retire_id as retireId, "
				+ "sf.enc_id as encId, "
				+ "sf.punish_id as punishId, "
				+ "sf.talent_team_id as talentTeamId, "
				+ "sf.edu_id as eduId, "
				+ "sf.family_id as familyId, "
				+ "sf.title_id as titleId, "
				+ "sf.party_log_id as partyLogId, "
				+ "sf.wadoc_id_add as wadocIdAdd, "
				+ "sf.wadoc_id_modify as wadocIdModify, "
				+ "sf.ass_id as assId, "
				+ "sf.nationduty_id as nationduty_id, "
				+ "sf.staff_id_his as staffIdHis, "
				+ "sf.out_staff_id_his as outStaffIdHis, "
				+ "sf.trial_id_his as trialIdHis, "
				+ "sf.psnjob_id_his as psnjobIdHis, "
				+ "sf.retire_id_his as retireIdHis, "
				+ "sf.enc_id_his as encIdHis, "
				+ "sf.punish_id_his as punishIdHis, "
				+ "sf.talent_team_id_his as talentTeamIdHis, "
				+ "sf.edu_id_his as eduIdHis, "
				+ "sf.family_id_his as familyIdHis, "
				+ "sf.title_id_his as titleIdHis, "
				+ "sf.party_log_id_his as partyLogIdHis, "
				+ "sf.wadoc_id_his as wadocIdHis, "
				+ "sf.ass_id_his as assIdHis, "
				+ "sf.nationduty_id_his as nationduty_id_his, "
				+ "sf.primary_id_his as primaryIdHis, "
				+ "sf.first_text as firstText, "
				+ "sf.second_text as secondText, "
				+ "sf.third_text as thirdText, "
				+ "sf.fourth_text as fourthText, "
				+ "sf.fifth_text as fifthText " + 
		      " from ati_base_form bf " + 
		      " left join " + 
		      " (select ati_base_form_id,ati_act_category_id, " +
		      "   max(case parameter when 'STAFF_ID' then param_value end) as STAFF_ID, " +
		      "   max(case parameter when 'OUT_STAFF_ID' then param_value end) as OUT_STAFF_ID, " +
		      "   max(case parameter when 'TRIAL_ID' then param_value end) as TRIAL_ID, " +
		      "   max(case parameter when 'PSNJOB_ID_MODIFY' then param_value end) as PSNJOB_ID_MODIFY, " +
		      "   max(case parameter when 'PSNJOB_ID_ADD' then param_value end) as PSNJOB_ID_ADD, " +
		      "   max(case parameter when 'RETIRE_ID' then param_value end) as RETIRE_ID, " +
		      "   max(case parameter when 'ENC_ID' then param_value end) as ENC_ID, " +
		      "   max(case parameter when 'PUNISH_ID' then param_value end) as PUNISH_ID, " +
		      "   max(case parameter when 'TALENT_TEAM_ID' then param_value end) as TALENT_TEAM_ID, " +
		      "   max(case parameter when 'EDU_ID' then param_value end) as EDU_ID, " +
		      "   max(case parameter when 'FAMILY_ID' then param_value end) as FAMILY_ID, " +
		      "   max(case parameter when 'TITLE_ID' then param_value end) as TITLE_ID, " +
		      "   max(case parameter when 'PARTY_LOG_ID' then param_value end) as PARTY_LOG_ID, " +
		      "   max(case parameter when 'WADOC_ID_ADD' then param_value end) as WADOC_ID_ADD, " +
		      "   max(case parameter when 'WADOC_ID_MODIFY' then param_value end) as WADOC_ID_MODIFY, " +
		      "   max(case parameter when 'ASS_ID' then param_value end) as ASS_ID, " +
		      "   max(case parameter when 'NATIONDUTY_ID' then param_value end) as NATIONDUTY_ID, " +
		      "   max(case parameter when 'STAFF_ID_HIS' then param_value end) as STAFF_ID_HIS, " +
		      "   max(case parameter when 'OUT_STAFF_ID_HIS' then param_value end) as OUT_STAFF_ID_HIS, " +
		      "   max(case parameter when 'TRIAL_ID_HIS' then param_value end) as TRIAL_ID_HIS, " +
		      "   max(case parameter when 'PSNJOB_ID_HIS' then param_value end) as PSNJOB_ID_HIS, " +
		      "   max(case parameter when 'RETIRE_ID_HIS' then param_value end) as RETIRE_ID_HIS, " +
		      "   max(case parameter when 'ENC_ID_HIS' then param_value end) as ENC_ID_HIS, " +
		      "   max(case parameter when 'PUNISH_ID_HIS' then param_value end) as PUNISH_ID_HIS, " +
		      "   max(case parameter when 'TALENT_TEAM_ID_HIS' then param_value end) as TALENT_TEAM_ID_HIS, " +
		      "   max(case parameter when 'EDU_ID_HIS' then param_value end) as EDU_ID_HIS, " +
		      "   max(case parameter when 'FAMILY_ID_HIS' then param_value end) as FAMILY_ID_HIS, " +
		      "   max(case parameter when 'TITLE_ID_HIS' then param_value end) as TITLE_ID_HIS, " +
		      "   max(case parameter when 'PARTY_LOG_ID_HIS' then param_value end) as PARTY_LOG_ID_HIS, " +
		      "   max(case parameter when 'WADOC_ID_HIS' then param_value end) as WADOC_ID_HIS, " +
		      "   max(case parameter when 'ASS_ID_HIS' then param_value end) as ASS_ID_HIS, " +
		      "   max(case parameter when 'NATIONDUTY_ID_HIS' then param_value end) as NATIONDUTY_ID_HIS, " +
		      "   max(case parameter when 'PRIMARY_ID_HIS' then param_value end) as PRIMARY_ID_HIS, " +
		      "   max(case parameter when 'FIRST_TEXT' then param_value end) as FIRST_TEXT, " +
		      "   max(case parameter when 'SECOND_TEXT' then param_value end) as SECOND_TEXT, " +
		      "   max(case parameter when 'THIRD_TEXT' then param_value end) as THIRD_TEXT, " +
		      "   max(case parameter when 'FOURTH_TEXT' then param_value end) as FOURTH_TEXT, " +
		      "   max(case parameter when 'FIFTH_TEXT' then param_value end) as FIFTH_TEXT " +
		      " from ati_specific_form " +
		      " group by ati_base_form_id,ati_act_category_id) sf " +
		      " on bf.ati_base_form_id = sf.ati_base_form_id " +
		      " where bf.proc_inst_id = ? ");
		List<Object> params = new ArrayList<Object>();
		if(null != procInstId) {
			params.add(procInstId);
		}
		AtiOaBaseObject oaBaseObject = super.jdbcFindObject(builder.toString(), params, AtiOaBaseObject.class);
		
		return oaBaseObject;
	}


}
